package com.example.backend.service.impl;

import com.example.backend.entity.Warehouse;
import com.example.backend.entity.Company;
import com.example.backend.mapper.WarehouseMapper;
import com.example.backend.service.WarehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WarehouseServiceImpl implements WarehouseService {
    @Autowired
    private WarehouseMapper warehouseMapper;

    @Override
    public int addWarehouse(Warehouse warehouse) {
        return warehouseMapper.insert(warehouse);
    }

    @Override
    public Warehouse getWarehouseById(Long id) {
        return warehouseMapper.selectById(id);
    }

    @Override
    public List<Warehouse> getAllWarehouses() {
        return warehouseMapper.selectAll();
    }

    @Override
    public int updateWarehouse(Warehouse warehouse) {
        return warehouseMapper.update(warehouse);
    }

    @Override
    public int deleteWarehouse(Long id) {
        return warehouseMapper.deleteById(id);
    }

    @Override
    public List<Company> getCompaniesByWarehouseId(Long warehouseId) {
        return warehouseMapper.selectCompaniesByWarehouseId(warehouseId);
    }
    
    @Override
    public List<Warehouse> getAvailableWarehousesByPort(Long portId) {
        return warehouseMapper.selectAvailableWarehousesByPort(portId);
    }

} 